﻿var menu, nav, toolbar;

RMS.front = {};
RMS.front = {
    loadPage: function (info) {
        var htmlForm = '<iframe width="100%", height="100%" src="' + info.url + '" /></iframe>';
        $('#main_content_panel').html(htmlForm);
    },
    initLayout: function () {
        //---------------------------------------------------------------------------
        //metro | orange | classic
        $.jqx.theme = 'web';    

        //---------------------------------------------------------------------------
        //Private method
        function loadSplitter() {
            $('#master_splitter_header').jqxSplitter({
                height: '100%', width: '100%',
                orientation: 'horizontal',
                splitBarSize: 2,
                showSplitBar: false,
                panels: [{ size: '31' }]
            });
            $('#master_splitter_navigation').jqxSplitter({
                width: '100%',
                splitBarSize: 4,
                showSplitBar: true,
                panels: [{ size: 220 }, { size: 200 }]
            });
            $('#master_splitter_toolbar').jqxSplitter({
                height: '100%', width: '100%',
                orientation: 'horizontal',
                splitBarSize: 2,
                showSplitBar: false,
                panels: [{ size: '28' }]
            });

            $('#master_content').jqxPanel({ width: '100%', height: '100%' });
        }
        function loadMenu() {
            menu = new CHierarchyMenu({
                container: '#main_menu_container',
                rootSelector: '#main_menu_bar',
                datasource: treedata,

                callbackItemSelect: function (el) {
                    var data = $(el).attr('item-data');
                    $('#master_content').prepend('Menu :: SelectedItem » ' + data + '</br>');
                }
            });
            menu.init();
        }
        function loadNavigation() {
            nav = new CHierarchyNavigation({
                container: '#main_navigation_container',
                classname: 'main_navigation',
                datasource: treedata,

                callbackItemSelect: function (el) {
                    var data = $(el).attr('item-data');
                    $('#master_content').prepend('Navigation :: SelectedItem » ' + data + '</br>');
                }
            });
            nav.init();
        }
        function loadToolbar() {
            contextToolbar = new CToolbar({
                container: '#main_toolbar_context',
                datasource: toolbar_data
            });
            contextToolbar.init();

            systemToolbar = new CToolbar({
                container: '#main_toolbar_system',
                datasource: toolbar_system_data
            });
            systemToolbar.init();            
        }

        //---------------------------------------------------------------------------
        //Main body funciton
        loadSplitter();
        loadMenu();
        loadNavigation();
        loadToolbar();
    }
};

$(function () {
    treedata = {menuitems : RMS.pub.convert2TreeData(treedataArr, 'menuitems')};
    console.log(Xtreedata);
    console.log(treedata);
    RMS.front.initLayout();
});